<h1>Clean Urls</h1>
<p class="devnote">Explain the different ways skeleton can handle URL's (both parameter based and clean)</p>

<h3>A_Http_Pathinfo</h3>

<p>This class adds/modifies the values in the Request object, so the code can be used with mod_rewrite and the Mapper, or without. The default parameters are <b>controller</b> and <b>action</b>, but these two parameter names can be changed by passing a different map to the constructor. </p>

<p>To use without mod_rewrite and only a Request class, URLs would look like:</p>

<p style="margin-left:50px; font-weight:bold;">www.mydomain.com?controller=people&action=list&sort=name</p>

<p>With mod_rewrite and this class, URLs look like:</p>

<p style="margin-left:50px; font-weight:bold;">www.mydomain.com/people/list/sort/name/</p>

<p>Either way the same values in the Request object would be set: 'controller', 'action' and 'sort'</p>

<p>A basic .htaccess file for use with mod_rewrite is:</p>

<pre>
RewriteEngine on
RewriteRule !\.[a-zA-Z0-9]{2,4}$ index.php
</pre>


<p>This is the format for mapping PATH_INFO values onto request vars:</p>

<pre class="prettyprint lang-php"><code>$map = array(
	'' => array(		// '' is the route array used when no match is found
		'controller',		// position in PATH_INFO and requestprotected to map onto
		'action',
		'id',
		),
	'date' => array(	// if 'date' is found in the first element of PATH_INFO use the map below
		'' => array(
			'controller',
			'year',
			'month',
			'day',
		),
	),
);
</code></pre>

<p>The mapper starts at the root level of the array and searches keys for a match on the first element in the PATH_INFO. If a key match is found it then uses the array under that key to search the next element in PATH_INFO. If no match is found then the [''] index in the array is used.  Every array should have a [''] key containing the route array to use to map PATH_INFO to Request vars.</p>

<p>In the example above, the PATH_INFO of "/view/person/Bob/" will map to the Request as "?controller=view&action=person&id=Bob" because 'view' does not match a key in the root array of the map, in this map that is '' and 'date'. The [''] array at the level where no match was found is used for the mapping. The PATH_INFO of "/date/2006/January/1st/" will map to the Request as "?controller=date&year=2006&month=January&day=1st" because 'date' matches a key in the map.</p>

<p>Additional parameters in the PATH_INFO past those defined in the map with be combined in pairs to request vars. For example, /view/person/Bob/age/42/height/84/ will map the the Reqest as "?controller=view&action=person&id=Bob&age=42&height=84". This can be turned off with the $map_extra_param_pairs parameter.</p>

<p>The position where mapping stopped is saves so additional maps can be applied to PATH_INFO. For example, the Front Http might map the first two values in PATH_INFO to the default /controller/action/ parameters. Different dispatched controllers may then set their own maps to map the parameters in PATH_INFO starting at the third parameter.</p>

<p>Here is an example use in the bootstrap:</p>

<pre class="prettyprint lang-php"><code>&lt;?php
// ...
$Request = new A_Http_Request();

$map = array(
	'' => array(		// '' is the route array used when no match is found
		'controller',		// position in PATH_INFO and requestprotected to map onto
		'action',
		'id',
		),
	'date' => array(	// if 'date' is found in the first element of PATH_INFO use the map below
		'' => array(
			'controller',
			'year',
			'month',
			'day',
		),
	),
);
$Pathinfo = new A_Http_Pathinfo($map);
// process Request according to map
$Pathinfo->run($Request);
// ...
</code></pre>